/*
 * @Author: zi.yang
 * @Date: 2022-02-08 22:11:18
 * @LastEditors: zi.yang
 * @LastEditTime: 2022-02-09 12:50:05
 * @Description: In User Settings Edit
 * @FilePath: \api-generator\app\controller\api-doc.js
 */
'use strict';
const Controller = require('egg').Controller;

class ApiDocController extends Controller {
  async PostAddApiDoc() {
    const { ctx } = this;
    const { body } = ctx.request;
    let docInfo = {};
    if (body.doc) {
      docInfo = body.doc;
    } else if (body.swaggerUrl) {
      docInfo = await ctx.service.home.getSwaggerDoc(body);
    }
    const result = await ctx.service.apiDoc.addApiDocInfo(docInfo);
    ctx.body = result;
  }

  async GetApiDocList() {
    const { ctx } = this;
    const result = await ctx.service.apiDoc.apiDocList();
    ctx.body = result;
  }
}

module.exports = ApiDocController;
